package edu.ucsd.cse135.gas.action.applicant;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import edu.ucsd.cse135.gas.bean.applicant.GreBean;
import edu.ucsd.cse135.gas.logic.GRE;
import edu.ucsd.cse135.gas.logic.applicant.Applicant;

public class GreAction extends Action {

	public GreAction() {
		super();
	}
	
	public ActionForward execute(ActionMapping mapping, ActionForm form, 
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		GRE greObject = new GRE();
		Applicant a = new Applicant();
		
		/** Show GRE results of applicant **/
		
		if(greObject.getGre(a.getApplicantId(request.getRemoteUser())))
		{
			
			GreBean greBean = new GreBean();

			greBean.setAnalytical(greObject.getAnalytical());
			greBean.setAnalyticalPercent(greObject.getAnalyticalPercent());
			greBean.setMonth(greObject.getMonth());
			greBean.setQuantitative(greObject.getQuantitative());
			greBean.setQuantitativePercent(greObject.getQuantitativePercent());
			greBean.setRegNo(greObject.getRegNo());
			greBean.setTotal(greObject.getTotal());
			greBean.setTotalPercent(greObject.getTotalPercent());
			greBean.setType(greObject.getType());
			greBean.setVerbal(greObject.getVerbal());
			greBean.setVerbalPercent(greObject.getVerbalPercent());
			greBean.setYear(greObject.getYear());
			
			request.setAttribute("greBean", greBean);
			
			return mapping.findForward("success");
		}
		else
		{
			request.setAttribute("noGre", true);
			
			return mapping.findForward("success");
		}
		
	}

}
